//
//  WhereGoViewController.m
//  OCUI3
//
//  Created by login on 15-6-30.
//  Copyright (c) 2015年 login. All rights reserved.
//

#import "WhereGoViewController.h"
#import "BaseTableViewCell.h"
#import "CellFactory.h"
#import "AppDelegate.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "PersonalCenterViewController.h"

@interface WhereGoViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>
{
    UITableView *mainTableView;
    NSMutableDictionary *_cellDict;
}
@end

@implementation WhereGoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    [self changeRootViewController];
    
    self.view.backgroundColor = [UIColor whiteColor];
    _cellDict = [NSMutableDictionary dictionary];
    [_cellDict setObject:@"ScrollViewCell" forKey:@(0)];
    [_cellDict setObject:@"ButtonCell" forKey:@(1)];
    [_cellDict setObject:@"ButtonCell" forKey:@(2)];
    [_cellDict setObject:@"ButtonCell" forKey:@(3)];
    [_cellDict setObject:@"ButtonCell" forKey:@(4)];

    [self initTableView];
}


- (void)initTableView
{
    mainTableView = [[UITableView alloc]initWithFrame:self.view.frame];
    mainTableView.delegate = self;
    mainTableView.dataSource = self;
    mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:mainTableView];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _cellDict.allKeys.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSArray *titleArray = @[@"0000",@"1111",@"2222",@"3333",@"4444"];
//    NSArray *colorArray = @[[UIColor whiteColor],[UIColor redColor],[UIColor yellowColor],[UIColor greenColor],[UIColor brownColor]];
    
    static NSString *cellIdentifier  = @"cellIdentifier";
    BaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        NSString *type = [NSString stringWithFormat:@"%@",[_cellDict objectForKey:@(indexPath.row)]];
        
        cell = [CellFactory getCellType:type andCellStyle:UITableViewCellStyleDefault withCellIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc]init];
    headerView.backgroundColor = [UIColor whiteColor];
    
    UISearchBar *search = [[UISearchBar alloc]initWithFrame:CGRectMake(30, 0, self.view.frame.size.width-60, 40)];
    search.placeholder = @"请输入";
    search.delegate = self;
    [search setTintColor:[UIColor blackColor]];
    search.searchBarStyle = UISearchBarStyleMinimal;
    
    [headerView addSubview:search];
    return headerView;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *type = [NSString stringWithFormat:@"%@",[_cellDict objectForKey:@(indexPath.row)]];
    
    return [CellFactory getCellHeight:type];
}

#pragma mark - UISearchBarDelegate
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    return YES;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
    
}

- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
